<template>
	<div class="cdkey-page">
		<div class="content">
			<el-row class="logo-row">
				<div class="logo">
					<!-- <img src="../../../../public/images/itclogo.png" alt="itclogo" /> -->
				</div>
				<h2>您的系统已过期</h2>
				<p>为了不影响您的使用，请联系相关业务员获取注册码</p>
			</el-row>
			<el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="70px" class="cdkey-rorm">
				<el-form-item label="序列号" prop=""><el-input v-model="ruleForm.uuid" readonly placeholder="将获取的序列号粘贴到此处"></el-input></el-form-item>
				<el-form-item label="注册码" prop="passnum" class="code-form-item">
					<el-input v-model.trim="ruleForm.passnum" placeholder="将获取的激活码粘贴到此处"></el-input>
				</el-form-item>
				<el-form-item class="send-item"><el-button type="primary" @click="submitForm('ruleForm')">激活</el-button></el-form-item>
			</el-form>
		</div>
		<el-dialog title="" class="tips-dialog" :visible.sync="dialogVisible" :close-on-click-modal="false" width="30%">
			<div class="part1">
				<p class="part-name">生效时间</p>
				<div class="time-tips">{{ resData.start_time }} ~ {{ resData.end_time }}</div>
			</div>
			<div class="part2">
				<p class="part-name">移动端激活模块</p>
				<div>
					<span class="tit">安卓</span>
					<el-radio-group v-model="resData.android" size="small">
						<el-radio label="1">已激活</el-radio>
						<el-radio label="0">未激活</el-radio>
					</el-radio-group>
				</div>
				<div>
					<span class="tit">IOS</span>
					<el-radio-group v-model="resData.ios" size="small">
						<el-radio label="1">已激活</el-radio>
						<el-radio label="0">未激活</el-radio>
					</el-radio-group>
				</div>
			</div>
		</el-dialog>
	</div>
</template>

<script>
export default {
	data() {
		return {
			ruleForm: {
				uuid: '',
				passnum: ''
			},
			rules: {
				passnum: [
					{
						required: true,
						message: '请输入注册码',
						trigger: 'blur'
					}
				]
			},
			dialogVisible: false,
			resData: {}
		};
	},
	watch: {},
	created() {
		this.getCode();
		this.checkGetauth();
	},
	methods: {
		// 系统过期问题，未过期跳回首页
        checkGetauth() {
			let success = res => {
				if(res.data === 'yes') {
					let host_addr = sessionStorage.getItem('host_addr')
					window.location.href = host_addr
				}
			};
			let fail = res => {};
			this.$ajax.get('/api/login/getauth', {
				params: {},
				func: { success, fail }
			});
        },
		getCode() {
			let success = res => {
				this.ruleForm.uuid = res.data;
			};
			let fail = res => {};
			this.$ajax.get('/index/checkpass/get_uuid2', {
				params: {},
				func: { success: success, fail: fail }
			});
		},
		submitForm(formName) {
			this.$refs[formName].validate(valid => {
				if (valid) {
					this.send();
				} else {
					console.log('error submit!!');
					return false;
				}
			});
		},
		send() {
			let success = res => {
				this.$message.error('激活成功');
				this.resData = res.data;
				this.dialogVisible = true;
				setTimeout(() => {
					this.dialogVisible = false;
					this.$router.push('/');
				}, 3000);
			};
			let fail = res => {
				this.$message.error('激活失败');
			};
			this.$ajax({
				url: '/index/checkpass/auto_pass',
				method: 'post',
				data: this.ruleForm,
				func: {
					success: success,
					fail: fail
				}
			});
		}
	}
};
</script>

<style lang="scss">
.cdkey-page {
	height: calc(100vh - 44px);
	display: grid;
	justify-content: center;
	align-content: center;
	.content {
		background-color: #fff;
		border-radius: 8px;
		padding: 30px 60px 50px;
		box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.1);
		.logo-row {
			.logo {
				text-align: center;
				img {
					width: 120px;
				}
			}
			h2 {
				font-size: 22px;
				font-weight: bold;
				line-height: 22px;
				padding: 40px 0 20px;
			}
			p {
				font-size: 14px;
				line-height: 20px;
				color: #999;
			}
		}
		.cdkey-rorm {
			width: 500px;
			padding-top: 25px;

			.send-item {
				padding-top: 20px;
				.el-button {
					width: 100%;
					height: 40px;
					padding: 0;
				}
			}
		}
	}
	.el-dialog__headerbtn .el-dialog__close {
		font-size: 28px;
		color: #409eff;
	}
	.tips-dialog {
		.part1 {
			padding-bottom: 20px;
		}
		.part-name {
			font-size: 18px;
			font-weight: bold;
		}
		.tit {
			font-size: 16px;
			line-height: 22px;
		}
		.time-tips,
		.el-radio-group {
			padding: 20px 40px;
		}
	}
}
</style>
